package com.limao.DBProvider;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.limao.CacheManager.BaseDataCacheManager;
import com.limao.CacheManager.CrowdPrestigeGoodsCache;
import com.limao.CacheManager.CrowdUserAuthCache;
import com.limao.CacheManager.user_rmbCacheManager;
import com.limao.DBDataClass.CrowdPrestigeGoodsDataClass;
import com.limao.DBDataClass.CrowdPrestigeOrderDataClass;
import com.limao.DBDataClass.CrowdUserAuthClass;
import com.limao.DbConnection.DbConnectionManager;
import com.limao.Model.LzPluginException;
import com.limao.Tool.CacheClass;
import com.limao.push.SysRmbRecTypeEnum;
import com.limao.push.pushToAPPTemplate;

public class CrowdPrestigeOrderProvider {

	private static class SysGoodsProviderContainer {
		private static CrowdPrestigeOrderProvider instance = new CrowdPrestigeOrderProvider();
	}

	public static CrowdPrestigeOrderProvider getInstance() {
		return SysGoodsProviderContainer.instance;
	}
	



	// 初始化
	private CrowdPrestigeOrderProvider() {

	}

	private CrowdPrestigeOrderDataClass encapOrderData(ResultSet rs) throws Exception{
		
		CrowdPrestigeOrderDataClass orderData = new CrowdPrestigeOrderDataClass();

		orderData.orderid=rs.getString("orderid");
		orderData.userid=rs.getString("userid");
		orderData.prestigeid=rs.getString("prestigeid");
		orderData.state=rs.getString("state");
		orderData.type=rs.getString("type");
		orderData.num=rs.getString("num");
		
		orderData.istest=rs.getString("istest");
		
		
		
		
		
		orderData.address=rs.getString("address");
		orderData.iscanback=rs.getString("iscanback");
		
		orderData.callbackprice=rs.getString("callbackprice");
		orderData.ctime=rs.getString("ctime");
		orderData.couriertime=rs.getString("couriertime");
		orderData.courier_sn=rs.getString("courier_sn");
		
		
		orderData.prestigename=rs.getString("prestigename");
		orderData.prestigeimage=rs.getString("prestigeimage");
		orderData.prestigeintro=rs.getString("prestigeintro");
		orderData.introimage=rs.getString("introimage");
		
		orderData.requirevalue=rs.getString("requirevalue");
		orderData.oldprice=rs.getString("oldprice");
		
		return orderData;
	}
	
	
	//某个某个商品的订单是否已存在
	public boolean isGet(int userid ,int prestigeid)
	{
		boolean flag=false;
		Connection con = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
			try {
				//是否已领取过
				con = DbConnectionManager.getConnection();
				pstmt = con.prepareStatement("select prestigeid from cd_sys_prestigeorder where userid=? and prestigeid=?");
				pstmt.setInt(1, userid);
				pstmt.setInt(2, prestigeid);
				rs =pstmt.executeQuery();
				if (rs.next()) {
					flag=true;
				}
				
			} catch (Exception e) {
				e.printStackTrace();
				flag=false;
			} finally {
				DbConnectionManager.closeConnection(rs, pstmt, con);
			}
		return flag;
		
	}
	
	//领取某个活跃商品的,生成订单
	public boolean CreateGet(int userid ,int prestigeid,CrowdPrestigeGoodsDataClass tmp)
	{
		boolean abortTransaction = false;
		Connection con = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		CrowdUserAuthClass authTmp= CrowdUserAuthCache.getInstance().getUser(userid);
		int istest=CacheClass.getIntValue(authTmp.istest);
			try {
				//是否已领取过
				con = DbConnectionManager.getTransactionConnection();
				pstmt = con.prepareStatement("insert into cd_sys_prestigeorder (userid,prestigeid,type,callbackprice,ctime,istest,iscanback) values (?,?,?,?,?,?,?) ");
				pstmt.setInt(1, userid);
				pstmt.setInt(2, prestigeid);
				pstmt.setInt(3, 0);
				pstmt.setFloat(4, CacheClass.getFloatValue(tmp.callbackprice));
				pstmt.setLong(5, CacheClass.getTime());
				pstmt.setInt(6, istest);
				pstmt.setInt(7, CacheClass.getIntValue(tmp.iscanback));
				
				pstmt.execute();
				
				//商品数量更新
				if(istest!=1){
					DbConnectionManager.fastcloseStmt(rs,pstmt);
					pstmt = con.prepareStatement("update cd_sys_prestigegoods set buynum=buynum+? where prestigeid=? and (buynum+1)<limitenum");
					pstmt.setInt(1,1);
					pstmt.setInt(2, prestigeid);
					if(pstmt.executeUpdate()!=1)
					{
						abortTransaction = true;
						throw new LzPluginException("商品缺货。");
					}
					
					CrowdPrestigeGoodsCache.getInstance().ClearObjectCache();
				}
				
				

			} catch (Exception e) {
				e.printStackTrace();
				abortTransaction=true;
			} finally {
				DbConnectionManager.closeTransactionConnection(rs, pstmt, con, abortTransaction);
			}
		return !abortTransaction;
		
	}	
	
	
	
	
	
	
	//活跃商品回购操作
	public boolean updateOrderCallBuy(int userid ,long orderid,CrowdPrestigeOrderDataClass tmp)
	{
		return updateOrderCallBuy(userid ,orderid,tmp,false);
	}
	
	//isRedBag  是否是红包的实物奖品回购 true是  false否
	public boolean updateOrderCallBuy(int userid ,long orderid,CrowdPrestigeOrderDataClass tmp,boolean isRedBag)
	{
		boolean abortTransaction = false;
		Connection con = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
			try {
				long t=CacheClass.getTime();
				con = DbConnectionManager.getTransactionConnection();
				//改变状态
				pstmt = con.prepareStatement("update cd_sys_prestigeorder set state=1,couriertime=? where orderid=? and userid=?");
				pstmt.setLong(1, t);
				pstmt.setLong(2, orderid);
				pstmt.setInt(3, userid);
				if(pstmt.executeUpdate()!=1)
				{
					abortTransaction = true;
					return !abortTransaction;
				}
				
				//用户增回收益
				DbConnectionManager.fastcloseStmt(rs,pstmt);
				pstmt = con.prepareStatement("update cd_user_rmb set nowrmb =(nowrmb +?) where userid=?");
				pstmt.setFloat(1, CacheClass.getFloatValue(tmp.callbackprice));
				pstmt.setInt(2, userid);
				if(pstmt.executeUpdate()!=1)
				{
					abortTransaction = true;
					return !abortTransaction;
					
				}
				//取更新后的新值
				String nowrmb="0";
				DbConnectionManager.fastcloseStmt(rs,pstmt);
				pstmt = con.prepareStatement("select nowrmb from cd_user_rmb where userid=?");
				pstmt.setInt(1, userid);
				rs=pstmt.executeQuery();
				if(rs.next())
				{
					nowrmb=rs.getString("nowrmb");
				}
				
				//收益记录
				pstmt = con.prepareStatement("INSERT INTO cd_sys_rmb (userid,payuserid,rmb,level,type,time,name,image,nowrmb) VALUES (?,?,?,?,?,?,?,?,?)");
				pstmt.setInt(1, userid);
				pstmt.setInt(2, userid);
				pstmt.setFloat(3, CacheClass.getFloatValue(tmp.callbackprice));
				pstmt.setInt(4, 0);
				if(isRedBag)
					pstmt.setInt(5, SysRmbRecTypeEnum.type1.getIntVlue());
				else
					pstmt.setInt(5, SysRmbRecTypeEnum.type2.getIntVlue());
				pstmt.setLong(6, t);
				pstmt.setString(7, "");
				pstmt.setString(8, "");
				pstmt.setBigDecimal(9, CacheClass.toBigDecimal(nowrmb));
				pstmt.execute();	
				
				//触发，系统消息发给收获人
				pushToAPPTemplate.NewMess_CallBuy(userid, CacheClass.getFloatValue(tmp.callbackprice));
				
				//更新缓存
				CrowdUserAuthCache.getInstance().ClearObjectCache(userid+"");

				
			
			} catch (Exception e) {
				abortTransaction = true;
				e.printStackTrace();
			} finally {
				DbConnectionManager.closeTransactionConnection(rs,pstmt, con,abortTransaction);
			}
		return !abortTransaction;
		
	}	
	
	
	
	//活跃商品申请发货操作
	public boolean updateOrderQuerySend(int userid ,long orderid,CrowdPrestigeOrderDataClass tmp,String address)
	{
		boolean abortTransaction = false;
		Connection con = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
			try {
				con = DbConnectionManager.getTransactionConnection();
				//改变状态
				pstmt = con.prepareStatement("update cd_sys_prestigeorder set state=0,address=? where orderid=? and userid=?");
				pstmt.setString(1, address);
				pstmt.setLong(2, orderid);
				pstmt.setInt(3, userid);
				pstmt.executeUpdate();
			
			} catch (Exception e) {
				abortTransaction = true;
				e.printStackTrace();
			} finally {
				DbConnectionManager.closeTransactionConnection(rs,pstmt, con,abortTransaction);
			}
		return !abortTransaction;
		
	}	
	
	//取用户所有获得的  活跃商品 列表
	public List<CrowdPrestigeOrderDataClass> Load_PrestigeOrder_All(int userid)
	{
		ArrayList<CrowdPrestigeOrderDataClass> list = new ArrayList<CrowdPrestigeOrderDataClass>();
		Connection con = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
			try {
				 //活跃商品 
				
				con = DbConnectionManager.getConnection();
				pstmt = con.prepareStatement("select po.*,pg.prestigename,pg.prestigeimage,pg.prestigeintro,pg.introimage,pg.requirevalue,pg.oldprice from cd_sys_prestigeorder po " +
						" left join cd_sys_prestigegoods pg on pg.prestigeid=po.prestigeid " +
						" where po.userid=? and po.type=0 order by po.orderid desc");
				pstmt.setInt(1, userid);
				rs = pstmt.executeQuery();
				while (rs.next()) {
					list.add(encapOrderData(rs));
				}

			} catch (Exception e) {
				e.printStackTrace();
				list .clear();
			} finally {
				DbConnectionManager.closeConnection(rs, pstmt, con);
			}

			return list;
	}

	//取用户所有获得的  实物奖品订单 列表
	public List<CrowdPrestigeOrderDataClass> Load_RedbagOrder_All(int userid)
	{
		ArrayList<CrowdPrestigeOrderDataClass> list = new ArrayList<CrowdPrestigeOrderDataClass>();
		Connection con = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
			try {
				 //实物奖品
				
				con = DbConnectionManager.getConnection();
				pstmt = con.prepareStatement("select po.*,pg.prestigename,pg.prestigeimage,pg.prestigeintro,pg.introimage,pg.requirevalue,pg.oldprice from cd_sys_prestigeorder po " +
						" left join cd_sys_prestigegoods pg on pg.prestigeid=po.prestigeid " +
						" where po.userid=? and po.type=3 order by po.orderid desc");
				pstmt.setInt(1, userid);
				rs = pstmt.executeQuery();
				while (rs.next()) {
					list.add(encapOrderData(rs));
				}

			} catch (Exception e) {
				e.printStackTrace();
				list .clear();
			} finally {
				DbConnectionManager.closeConnection(rs, pstmt, con);
			}

			return list;
	}
	
	//取某个活跃商品订单信息
	public CrowdPrestigeOrderDataClass Load_PrestigeOrder_byOrderid(long orderid)
	{
		CrowdPrestigeOrderDataClass tmp = new CrowdPrestigeOrderDataClass();
		Connection con = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
			try {
				 //活跃订单
				con = DbConnectionManager.getConnection();
				pstmt = con.prepareStatement("select po.*,pg.prestigename,pg.prestigeimage,pg.prestigeintro,pg.introimage,pg.requirevalue,pg.oldprice from cd_sys_prestigeorder po " +
						" left join cd_sys_prestigegoods pg on pg.prestigeid=po.prestigeid " +
						" where po.orderid=? ");
				pstmt.setLong(1, orderid);
				rs = pstmt.executeQuery();
				if (rs.next()) {
					tmp=encapOrderData(rs);
				}

			} catch (Exception e) {
				e.printStackTrace();
				tmp=null;
			} finally {
				DbConnectionManager.closeConnection(rs, pstmt, con);
			}

			return tmp;
	}
	
	
	
	//购买虚拟币商品的,生成订单
	public boolean CreateVrGet(int userid ,int prestigeid,int num,CrowdPrestigeGoodsDataClass tmp)
	{
		boolean abortTransaction = false;
		Connection con = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		
		CrowdUserAuthClass authTmp= CrowdUserAuthCache.getInstance().getUser(userid);
		int istest=CacheClass.getIntValue(authTmp.istest);
			try {
				//扣除虚拟币
				long virtualcoin=num*CacheClass.getLongValue(tmp.requirevalue);
				
				con = DbConnectionManager.getTransactionConnection();
				pstmt = con.prepareStatement("update cd_user_rmb set virtualcoin=virtualcoin-? where userid=?");
				pstmt.setBigDecimal(1,CacheClass.getBigDecimal(virtualcoin+""));
				pstmt.setInt(2, userid);
				if(pstmt.executeUpdate()!=1)
				{
					abortTransaction = true;
					throw new LzPluginException("狸猫豆　不足。");
				}
				//取更新后的新值
				String newlogvalue="0";
				DbConnectionManager.fastcloseStmt(rs,pstmt);
				pstmt = con.prepareStatement("select virtualcoin from cd_user_rmb where userid=?");
				pstmt.setInt(1, userid);
				rs=pstmt.executeQuery();
				if(rs.next())
				{
					newlogvalue=rs.getString("virtualcoin");
				}
				//生成虚拟币记录
				DbConnectionManager.fastcloseStmt(rs,pstmt);
				pstmt = con.prepareStatement("insert into cd_sys_prestigelog (userid,payuserid,cate,type,logvalue,newlogvalue,ctime) values (?,?,?,?,?,?,?);");
				pstmt.setInt(1, userid);
				pstmt.setInt(2, userid);
				pstmt.setInt(3, 1);
				pstmt.setInt(4, 4);//4虚拟币(睛好)购物消耗
				pstmt.setBigDecimal(5, CacheClass.getBigDecimal((0-virtualcoin)+""));
				pstmt.setBigDecimal(6, CacheClass.getBigDecimal(newlogvalue));
				pstmt.setLong(7, CacheClass.getTime());
				pstmt.execute();
				
				//生成订单
				DbConnectionManager.fastcloseStmt(rs,pstmt);
				pstmt = con.prepareStatement("insert into cd_sys_prestigeorder (userid,prestigeid,num,state,type,callbackprice,ctime,istest,iscanback) values (?,?,?,?,?,?,?,?,?) ");
				pstmt.setInt(1, userid);
				pstmt.setInt(2, prestigeid);
				pstmt.setInt(3, num);
				pstmt.setInt(4, -1);
				pstmt.setInt(5, 1);
				pstmt.setFloat(6, CacheClass.getFloatValue(tmp.callbackprice));
				pstmt.setLong(7, CacheClass.getTime());
				pstmt.setInt(8, istest);
				pstmt.setInt(9, CacheClass.getIntValue(tmp.iscanback));
				pstmt.execute();
				
				//商品数量更新
				if(istest!=1)
				{
					DbConnectionManager.fastcloseStmt(rs,pstmt);
					pstmt = con.prepareStatement("update cd_sys_prestigegoods set buynum=buynum+? where prestigeid=? and (buynum+?)<limitenum");
					pstmt.setInt(1,num);
					pstmt.setInt(2, prestigeid);
					pstmt.setInt(3,num);
					if(pstmt.executeUpdate()!=1)
					{
						abortTransaction = true;
						throw new LzPluginException("商品缺货。");
					}
				}


			} catch (Exception e) {
				e.printStackTrace();
				abortTransaction = true;
			} finally {
				DbConnectionManager.closeTransactionConnection(rs,pstmt, con,abortTransaction);
			}
			
			if(!abortTransaction)
			{
				user_rmbCacheManager.getInstance().ClearObjectCache(userid+"");
				CrowdUserAuthCache.getInstance().ClearObjectCache(userid+"");
				CrowdPrestigeGoodsCache.getInstance().ClearObjectCache();
				
			}
		return !abortTransaction;
		
	}	
	
	
	
	//取用户所有   虚拟币商城订单列表
	public List<CrowdPrestigeOrderDataClass> Load_PrestigeOrder_Vr_All(int userid)
	{
		ArrayList<CrowdPrestigeOrderDataClass> list = new ArrayList<CrowdPrestigeOrderDataClass>();
		Connection con = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
			try {
				 //活跃商品
				con = DbConnectionManager.getConnection();
				pstmt = con.prepareStatement("select po.*,pg.prestigename,pg.prestigeimage,pg.prestigeintro,pg.introimage,pg.requirevalue,pg.oldprice from cd_sys_prestigeorder po " +
						" left join cd_sys_prestigegoods pg on pg.prestigeid=po.prestigeid " +
						" where po.userid=? and po.type=1 order by po.orderid desc");
				pstmt.setInt(1, userid);
				rs = pstmt.executeQuery();
				while (rs.next()) {
					list.add(encapOrderData(rs));
				}

			} catch (Exception e) {
				e.printStackTrace();
				list .clear();
			} finally {
				DbConnectionManager.closeConnection(rs, pstmt, con);
			}

			return list;
	}

	//虚拟币商城订单回购操作
	public boolean updateOrderVrCallBuy(int userid ,long orderid,CrowdPrestigeOrderDataClass tmp)
	{
		boolean abortTransaction = false;
		Connection con = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		float virtualcoinice=CacheClass.getIntValue(tmp.num)*CacheClass.getFloatValue(tmp.callbackprice);
			try {
				long t=CacheClass.getTime();
				con = DbConnectionManager.getTransactionConnection();
				//改变状态
				pstmt = con.prepareStatement("update cd_sys_prestigeorder set state=1,couriertime=? where orderid=? and userid=?");
				pstmt.setLong(1, t);
				pstmt.setLong(2, orderid);
				pstmt.setInt(3, userid);
				if(pstmt.executeUpdate()!=1)
				{
					abortTransaction = true;
					return !abortTransaction;
				}
				
				//用户增回 虚拟币(雾霾)
				
				DbConnectionManager.fastcloseStmt(rs,pstmt);
				pstmt = con.prepareStatement("update cd_user_rmb set virtualcoinice=virtualcoinice+?,maxvirtualcoin=maxvirtualcoin+? where userid=?");
				pstmt.setBigDecimal(1,CacheClass.getBigDecimal(virtualcoinice+""));
				pstmt.setBigDecimal(2,CacheClass.getBigDecimal(virtualcoinice+""));
				pstmt.setInt(3, userid);
				if(pstmt.executeUpdate()!=1)
				{
					abortTransaction = true;
					throw new LzPluginException("用户增回 虚拟币(回购中)　失败");
				}

				//取更新后的新值
				String newlogvalue="0";
				DbConnectionManager.fastcloseStmt(rs,pstmt);
				pstmt = con.prepareStatement("select virtualcoinice from cd_user_rmb where userid=?");
				pstmt.setInt(1, userid);
				rs=pstmt.executeQuery();
				if(rs.next())
				{
					newlogvalue=rs.getString("virtualcoinice");
				}
				
				//增加记录
				DbConnectionManager.fastcloseStmt(rs,pstmt);
				pstmt = con.prepareStatement("insert into cd_sys_prestigelog (userid,payuserid,cate,type,logvalue,newlogvalue,ctime) values (?,?,?,?,?,?,?);");
				pstmt.setInt(1, userid);
				pstmt.setInt(2, userid);
				pstmt.setInt(3, 1);
				pstmt.setInt(4, 5);//回购增加虚拟币(雾霾)
				pstmt.setBigDecimal(5, CacheClass.getBigDecimal(virtualcoinice+""));
				pstmt.setBigDecimal(6, CacheClass.getBigDecimal(newlogvalue));
				pstmt.setLong(7, t);
				pstmt.execute();
				
			
			} catch (Exception e) {
				abortTransaction = true;
				e.printStackTrace();
			} finally {
				DbConnectionManager.closeTransactionConnection(rs,pstmt, con,abortTransaction);
			}
			
			if(!abortTransaction)
			{
				//更新缓存
				user_rmbCacheManager.getInstance().ClearObjectCache(userid+"");
				CrowdUserAuthCache.getInstance().ClearObjectCache(userid+"");
				//触发，系统消息发给收获人
				pushToAPPTemplate.NewMess_CallVrCallBack(userid, virtualcoinice);
			}
			
			return !abortTransaction;
		
	}	
	
	
	
	//现货瓶数申请发货,生成订单
	public boolean CreateVrGoodsOrder(int userid ,int vrgoodsid,int num,String address)
	{
		boolean abortTransaction = false;
		Connection con = null;
		PreparedStatement pstmt = null;
		ResultSet rs = null;
		
		CrowdUserAuthClass authTmp= CrowdUserAuthCache.getInstance().getUser(userid);
		int istest=CacheClass.getIntValue(authTmp.istest);
		try {
			//扣除现货瓶数
			Date now=new Date();
			con = DbConnectionManager.getTransactionConnection();
			pstmt = con.prepareStatement("update cd_user_num set num=(num-?) where userid=? and vrgoodsid=? and (num-?)>=0;");
			pstmt.setBigDecimal(1, CacheClass.toBigDecimal(num+""));
			pstmt.setInt(2, userid);
			pstmt.setInt(3, vrgoodsid);
			pstmt.setBigDecimal(4, CacheClass.toBigDecimal(num+""));
			if(pstmt.executeUpdate()!=1)
			{
				abortTransaction = true;
				throw new LzPluginException("出错，瓶数不足。");
			}
			
			//生成订单
			int OrderFinishDays=CacheClass.getIntValue(BaseDataCacheManager.getInstance().Load_Param("OrderFinishDays").trim());
			DbConnectionManager.fastcloseStmt(rs,pstmt);
			pstmt = con.prepareStatement("insert into cd_sys_numorder (userid,vrgoodsid,num,address,state,finishdays,ctime) values (?,?,?,?,?,?,?) ");
			pstmt.setInt(1, userid);
			pstmt.setInt(2, vrgoodsid);
			pstmt.setInt(3, num);
			pstmt.setString(4, address);
			pstmt.setInt(5, 1);
			pstmt.setInt(6, OrderFinishDays);
			pstmt.setLong(7, now.getTime());
			pstmt.execute();				
			
			//查得刚生成的订单id
			long orderid=0;
			DbConnectionManager.fastcloseStmt(rs,pstmt);
			pstmt = con.prepareStatement("select orderid from cd_sys_numorder where userid=? and ctime=? ;");
			pstmt.setInt(1, userid);
			pstmt.setLong(2, now.getTime());
			rs=pstmt.executeQuery();
			if(rs.next())
			{
				orderid=rs.getInt("orderid");
			}
			else
			{
				abortTransaction = true;
				throw new LzPluginException("出错，瓶数不足。");
			}
			//取瓶数更新后的值
			String manowtotalrmb="0";
			DbConnectionManager.fastcloseStmt(rs,pstmt);
			pstmt = con.prepareStatement("select num from cd_user_num where userid=? and vrgoodsid=? ;");
			pstmt.setInt(1, userid);
			pstmt.setInt(2, vrgoodsid);
			rs=pstmt.executeQuery();
			if(rs.next())
			{
				manowtotalrmb=rs.getString("num");
			}
			
			//出售者瓶数变动记录
			DbConnectionManager.fastcloseStmt(rs,pstmt);
			pstmt = con.prepareStatement("INSERT INTO cd_sys_rmb (userid,payuserid,rmb,level,type,time,name,image,nowrmb,orderid,vrgoodsid) VALUES (?,?,?,?,?,?,?,?,?,?,?)");
			pstmt.setInt(1, userid);
			pstmt.setInt(2, 0);
			pstmt.setBigDecimal(3, CacheClass.toBigDecimal((0-num)+"") );
			pstmt.setInt(4, 0);
			pstmt.setInt(5, SysRmbRecTypeEnum.type110.getIntVlue()); 
			pstmt.setLong(6, now.getTime());
			pstmt.setString(7, "系统");
			pstmt.setString(8, "");
			pstmt.setBigDecimal(9, CacheClass.toBigDecimal(manowtotalrmb));
			pstmt.setLong(10, orderid);
			pstmt.setLong(11, vrgoodsid);
			pstmt.execute();

		} catch (Exception e) {
			e.printStackTrace();
			abortTransaction = true;
		} finally {
			DbConnectionManager.closeTransactionConnection(rs,pstmt, con,abortTransaction);
		}
		
		if(!abortTransaction)
		{
			user_rmbCacheManager.getInstance().ClearObjectCache(userid+"");
			CrowdUserAuthCache.getInstance().ClearObjectCache(userid+"");
			CrowdPrestigeGoodsCache.getInstance().ClearObjectCache();
			
		}
		return !abortTransaction;
		
	}	
	
	
	
}
